added Feb 2001 SDK
[windows-sources.git] / shared source / vb / language / shared / templateutil.h
blob3854fb39f18fd7308444d337537de155535ca095
1 //-------------------------------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Template Utilities
6 //
7 //-------------------------------------------------------------------------------------------------
9 #pragma once
11 class TemplateUtil
13 public:
14 template <class T>
15 static
16 void Swap(_Inout_ T **left, _Inout_ T **right) throw()
18 T *temp = *right;
19 *right = *left;
20 *left = temp;
23 //-------------------------------------------------------------------------------------------------
25 // Useful CompileTime function that will allow you to assert an inheritance relationship between
26 // two types. Very helpful in certain template sceanrios.
28 // Use a static cast here because it will prevent operator consideration.
30 //-------------------------------------------------------------------------------------------------
31 template <typename Parent, typename Child>
32 static
33 void CompileAssertIsChildOf()
35 #if DEBUG
36 Parent *pParent = NULL;
37 Child *pChild = NULL;
38 pParent = static_cast<Parent*>(pChild);
39 #endif
42 //-------------------------------------------------------------------------------------------------
44 // Several of our hashing algorithms require the size of a key be a multiple of the size of
45 // a pointer. This function will prevent a compilation in DEBUG mode unless this is satisifed
47 //-------------------------------------------------------------------------------------------------
48 template <typename T>
49 static
50 void CompileAssertSizeIsPointerMultiple()
52 #if DEBUG
53 COMPILE_ASSERT(0 == (sizeof(T) % sizeof(void*)));
54 #endif